<?php

/**
 * @author Martin Pernica
 * @copyright 2009
 */

Text::h1( Lang::getBack('com_content', 'admin') );
 
if(empty($_GET['a'])){
    
echo '<table cellspacing="15" cellpadding="15">';
echo '<tr><td><a href="'.$_SERVER['PHP_SELF'] .'?'. $_SERVER['QUERY_STRING'] .'&a=new"><img src="../libs/icons/add.png" /> '.Lang::getBack('com_content', 'new').'</a></td></tr>';
echo '</table><br />';


$query = Registry::get('db')->query("SELECT * FROM {prefix}articles ORDER BY date DESC");
echo '<table cellspacing="20" cellpadding="30" class="clean_table">';
echo '<tr><th>'.Lang::getBack('com_content', 'title').'</th><th>'.Lang::getBack('com_content', 'category').'</th><th>'.Lang::getBack('com_content', 'author').'</th><th>'.Lang::getBack('com_content', 'date').'</th><th>'.Lang::getBack('com_content', 'frontage').'</th><th>'.Lang::getBack('com_content', 'notice').'</th><th>'.Lang::getBack('com_content', 'closed').'</th><th>'.Lang::getBack('com_content', 'published').'</th><th>'.Lang::getBackGlobal('action').'</th></tr>';

while($data = $query->fetch_array()){
    $closed = ($data['closed'] == 1) ? 'lock_delete.png' : 'lock_open.png';
	$published = ($data['published'] == 1) ? 'tick.png' : 'exclamation.png';
	$frontpage = ($data['frontpage'] == 1) ? 'page_add.png' : 'page_delete.png';
	$notice = ($data['notice'] == 1) ? 'note_add.png' : 'note_delete.png';
	echo '<tr><td>'.$data['title'].'</td><td>'.getCategoryName($data['cat_id']).'</td><td>'.getUsernameFromDB($data['author_id']).'</td><td>'.$data['date'].'</td><td><img src="../libs/icons/'.$frontpage.'" /></td><td><img src="../libs/icons/'.$notice.'" /></td><td><img src="../libs/icons/'.$closed.'" /></td><td><img src="../libs/icons/'.$published.'" /></td><td><a href="'.$_SERVER['PHP_SELF'] .'?'. $_SERVER['QUERY_STRING'].'&a=delete&id='.$data['id'].'"><img src="../libs/icons/delete.png" /></a>&nbsp;&nbsp;<a href="'.$_SERVER['PHP_SELF'] .'?'. $_SERVER['QUERY_STRING'].'&a=edit&id='.$data['id'].'"><img src="../libs/icons/style_edit.png" /></a></td></tr>';
}
echo '</table>';

}else {
	switch($_GET['a']){
		case 'new':
		require 'new.php';
		break;
		
		case 'delete':
		require 'delete.php';
		break;
		
		case 'edit':
		require 'edit.php';
		break;
	}
}
?>